package com.imut.oa.controller.user;

import com.imut.oa.common.BaseResponse;
import com.imut.oa.common.ResultUtils;

import com.imut.oa.pojo.entity.Task;
import com.imut.oa.service.TaskService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/task")
@Slf4j
@Tag(name = "任务")
public class UserTaskController {
    @Autowired
    private TaskService taskService;

    /**
     * 获取任务列表
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    @Operation(summary = "获取任务列表")
    public BaseResponse<?> getTaskHistory(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize) {
        List<Task> history = taskService.getTaskHistory(page, pageSize);
        return ResultUtils.success(history);
    }
    @PostMapping("/accept")
    @Operation(summary = "接受任务")
    public BaseResponse<?> acceptTask(@RequestParam("taskId") Long taskId) {
        taskService.acceptTask(taskId);
        return ResultUtils.success(null,"接受任务成功");
    }
    @PostMapping("/complete")
    @Operation(summary = "完成任务")
    public BaseResponse<?> completeTask(@RequestParam("taskId") Long taskId) {
        taskService.completeTask(taskId);
        return ResultUtils.success(null,"完成任务成功");
    }
}
